package com.zhentao.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.UserFeedbackMapper;
import com.zhentao.pojo.UserFeedback;
import com.zhentao.service.UserFeedbackService;
import com.zhentao.vo.Query;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
* @author lenovo
* @description 针对表【user_feedback】的数据库操作Service实现
* @createDate 2025-08-19 08:48:57
*/
@Service
public class UserFeedbackServiceImpl extends ServiceImpl<UserFeedbackMapper, UserFeedback>
    implements UserFeedbackService{


    @Override
    public Page<UserFeedback> findPage(Query query) {
        // 1. 处理分页参数，设置默认值（避免null）
        int currentPage = Objects.requireNonNullElse(query.getPage(), 1); // 默认为第1页
        int pageSize = Objects.requireNonNullElse(query.getSize(), 10);   // 默认为每页10条
        Page<UserFeedback> pageResult = new Page<>(currentPage, pageSize);

        // 2. 构建查询条件（动态拼接）
        QueryWrapper<UserFeedback> queryWrapper = new QueryWrapper<>();
        // 若标题不为空，则添加模糊查询条件
        if (StringUtils.isNotBlank(query.getProblemType())) {
            queryWrapper.like("problem_type", query.getProblemType());
        }


        // 3. 执行分页查询
        return baseMapper.selectPage(pageResult, queryWrapper);
    }
}




